<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements.  See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership.  The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
-->

<app-help-massage-show
  [help_massage_content]="'define.help' | i18n"
  [guild_link]="'define.help.link' | i18n"
  [module_name]="'menu.advanced.define'"
  [icon_name]="'code'"
></app-help-massage-show>
<nz-divider></nz-divider>

<nz-layout style="min-height: 100vh">
  <nz-sider style="height: 100%; overflow: auto; margin: 4px" [nzTrigger]="null">
    <ul nz-menu nzTheme="light" nzMode="inline" nzInlineCollapsed="false">
      <li *ngIf="currentApp != null" style="text-align: center; margin-top: 12px">
        <button nzGhost nz-button nzType="primary" nzSize="small" (click)="onNewMonitorDefine()">
          <i nz-icon nzType="appstore-add" nzTheme="outline"></i>
          {{ 'define.new' | i18n }}
        </button>
      </li>
      <li *ngFor="let menuItem of appMenusArr" nz-submenu [nzTitle]="renderCategoryName(menuItem[0])">
        <ul>
          <li nz-menu-item *ngFor="let app of menuItem[1]" [nzSelected]="app.selected" style="padding-left: 24px">
            <button
              *ngIf="app.hide == true || app.hide == undefined"
              nz-button
              nzSize="small"
              nz-tooltip
              [nz-tooltip]="'define.hide-true.tip' | i18n"
              nz-popconfirm
              [nzPopconfirmTitle]="'define.hide-true.confirm' | i18n"
              (nzOnConfirm)="updateAppTemplateConfig(app.value, !app.hide)"
              nzPopconfirmPlacement="bottom"
            >
              <i nz-icon nzType="eye-invisible" nzTheme="outline"></i>
            </button>
            <button
              *ngIf="app.hide == false"
              nz-button
              nzSize="small"
              nz-tooltip
              [nz-tooltip]="'define.hide-false.tip' | i18n"
              nz-popconfirm
              [nzPopconfirmTitle]="'define.hide-false.confirm' | i18n"
              (nzOnConfirm)="updateAppTemplateConfig(app.value, !app.hide)"
              nzPopconfirmPlacement="bottom"
            >
              <i nz-icon nzType="eye" nzTheme="outline"></i>
            </button>
            <button nz-button nzSize="small" routerLink="/setting/define" [queryParams]="{ app: app.value }">
              <span style="margin-left: 6px">
                {{ app.label }}
              </span>
            </button>
          </li>
        </ul>
      </li>
    </ul>
  </nz-sider>
  <nz-layout>
    <nz-content>
      <div style="margin: 10px 10px 4px 10px">
        <button nzGhost *ngIf="currentApp != null" nz-button nzType="primary" routerLink="/monitors" [queryParams]="{ app: currentApp }">
          <i nz-icon nzType="file-text" nzTheme="outline"></i>
          {{ 'app-' + currentApp + '.yml' }}
          <i nz-icon nzType="more" nzTheme="outline"></i>
        </button>
        <button *ngIf="code != originalCode" nz-button nzType="primary" [nzLoading]="saveLoading" (click)="onSaveAndApply()">
          <i nz-icon nzType="save" nzTheme="outline"></i>
          {{ 'define.save-apply' | i18n }}
        </button>
        <button *ngIf="false" nz-button nzType="primary" (click)="onDeleteDefineYml()">
          <i nz-icon nzType="up-circle" nzTheme="outline"></i>
          {{ 'define.enable' | i18n : { app: currentApp } }}
        </button>
        <button *ngIf="false" nz-button nzDanger nzType="primary" (click)="onDeleteDefineYml()">
          <i nz-icon nzType="down-circle" nzTheme="outline"></i>
          {{ 'define.disable' | i18n : { app: currentApp } }}
        </button>
        <button *ngIf="currentApp != null" nz-button nzDanger nzType="primary" (click)="onDeleteDefineYml()">
          <i nz-icon nzType="delete" nzTheme="outline"></i>
          {{ 'define.delete' | i18n : { app: currentApp } }}
        </button>

        <nz-switch
          style="margin-right: 25px; float: right"
          [ngModel]="dark"
          (ngModelChange)="onDarkModeChange($event)"
          [nzUnCheckedChildren]="unchecked"
          [nzCheckedChildren]="checked"
        ></nz-switch>
        <ng-template #unchecked>
          <span nz-icon nzType="bulb"></span>
        </ng-template>
        <ng-template #checked>
          <span nz-icon nzType="poweroff"></span>
        </ng-template>
      </div>
      <div style="margin: 4px 10px 4px 4px; height: 100%; width: 100%">
        <nz-code-editor
          class="editor"
          [nzLoading]="loading"
          [nzOriginalText]="originalCode"
          [(ngModel)]="code"
          [nzEditorMode]="'diff'"
          [nzEditorOption]="{ language: 'yaml', theme: 'vs-dark', folding: true }"
        ></nz-code-editor>
      </div>
    </nz-content>
  </nz-layout>
</nz-layout>
